﻿@model YouWei.Infrastructure.Entity.WxGroup
@{
    ViewBag.Title = "微信群管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="content-header">
    <h1>
        微信群管理
        <small></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li><a href="javascript:void(0)" id="PrePage">群组管理</a></li>
        <li><a href="javascript:void(0)" id="preBtn">微信群列表</a></li>
        <li class="active">微信群管理</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <form class="form-horizontal" id="form1">
                        <div class="box-body">
                            <input type="hidden" name="ID" value="@Model.WxGroupID" />
                            <div class="form-group">
                                <label class="col-sm-2 control-label">名称</label>
                                <div class="col-sm-3">
                                    <input type="text" name="txtName" id="txtName" value="@Model.Name" class="form-control" maxlength="100">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">昵称</label>
                                <div class="col-sm-3">
                                    <input type="text" name="txtNickName" id="txtNickName" value="@Model.NickName" class="form-control" maxlength="50">
                                </div>
                            </div>
                           
                            <div class="form-group">
                                <label class="col-sm-2 control-label">头像地址</label>
                                <div class="col-sm-3">
                                    <input type="text" name="txtHeadImgUrl" id="txtHeadImgUrl" value="@Model.HeadImgUrl" class="form-control" maxlength="400">
                                </div>
                            </div>
                            @if (Model.WxGroupID > 0)
                            {
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">数量</label>
                                    <div class="col-sm-3">
                                        <input type="text" name="txtTotal" id="txtTotal" value="@Model.Total" class="form-control">
                                    </div>
                                </div>
                            }
                            else
                            {
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">数量</label>
                                    <div class="col-sm-3">
                                        <input type="text" name="txtTotal" id="txtTotal" value="" class="form-control">
                                    </div>
                                </div>
                            }
                            <div class="form-group">
                                <label class="col-sm-2 control-label">管理员</label>
                                <div class="col-sm-3">
                                    <input type="text" name="txtManager" id="txtManager" value="@Model.Manager" class="form-control" maxlength="50">
                                </div>
                            </div>
                          
                            <div class="form-group">
                                <label class="col-sm-2 control-label">二维码地址</label>
                                <div class="col-sm-3">
                                    <div id="HeadImageUrl" class="dm-uploader">
                                        <div role="button" class="btn btn-primary mr-2">
                                            <i class="fa fa-fw fa-folder-o"></i>图片上传
                                            <input type="file" title="Click to add Files">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"></label>
                                <div class="col-sm-3">
                                    <div class="over-hidden" style="">
                                        @if (Model.WxGroupID > 0)
                                        {
                                            <div id="divImg" class="img-wrapper-titlephoto fl" style="display: block;">
                                                <img id="imgPhoto" style="width: 360px; height: 160px;border:1px solid #ccc " src="@string.Format("{0}/{1}", YouWei.Utility.ConfigHelper.GetAppSettingValue("CommentImageServerUrl"), Model.QrCodeUrl)" />
                                                <input type="hidden" id="hidDbUrl" value="@Model.QrCodeUrl" />

                                            </div>
                                        }
                                        else
                                        {
                                            <div id="divImg" class="img-wrapper-titlephoto fl" style="display: none;">
                                                <img id="imgPhoto" style="width: 360px; height: 160px;border:1px solid #ccc " src="" />
                                                <input type="hidden" id="hidDbUrl" />

                                            </div>
                                        }
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">描述</label>
                                <div class="col-sm-3">
                                    <textarea name="txtDesc" id="txtDesc" class="form-control" maxlength="100">@Model.Desc</textarea>
                                </div>
                            </div>
                            <!-- /.box-body -->
                            <div class="box-footer text-center">
                                <button class="btn btn-info" type="button" id="btnSave">保存</button>
                            </div>
                        </div>
                        <!-- /.box-footer -->
                    </form>
                </div>
                <div class="box-footer clearfix ">
                </div>
                <!-- /.box-body -->
                <!-- /.box -->
            </div>
        </div>
    </div>
</section>
@section scriptsBottom{
    <script type="text/javascript">
        var userId = 0; //是否是添加页面，如果是编辑页则判断条件增加ID
        $(document).ready(function () {

            initFormValidate();
            binds();
            renderImg();

        });

        //保存
        function save() {
            var carGroupId = @ViewBag.CarGroupId;
            var ccid = @Model.WxGroupID;
            var bootstrapValidator = $("#form1").data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                var url = '@Url.Action("SaveWxGroup", "Public")';
                var options = {
                    url: url,
                    type: "POST",
                    data: {
                        CarGroupID: carGroupId,
                        Name: $("#txtName").val(),
                        Total: $("#txtTotal").val(),
                        Desc: $("#txtDesc").val(),
                        Manager: $("#txtManager").val(),
                        WxGroupID:ccid,
                        QrCodeUrl:$("#hidDbUrl").val(),
                        HeadImgUrl:$("#txtHeadImgUrl").val(),
                        NickName:$("#txtNickName").val()
                    },
                    success: function (o) {
                        if (o.status == 0) {
                            BMCW.msg("保存成功", function () {
                                location.href='@Url.Action("WxGroupList", "Public")?cid='+carGroupId;
                            });
                        } else {
                            BMCW.alert(o.message);
                        }
                    }
                };

                BMCW.ajax(options);
            }
        }
        function binds() {
            //保存
            $("#btnSave").click(function () {
                save();
            });
            $("#preBtn").click(function () {
                var url = '@Url.Action("WxGroupList", "Public")?cid='+@ViewBag.CarGroupId;
                location.href = url;
            });
            $("#PrePage").click(function () {
                var url = '@Url.Action("CarGroupList", "Public")';
                location.href = url;
            });
        }

        function initFormValidate() {
            $("#form1").bootstrapValidator({
                submitHandler: function (valiadtor, loginForm, submitButton) {
                    valiadtor.defaultSubmit();
                },
                fields: {
                    txtName: {
                        validators: {
                            notEmpty: {
                                message: '请输入名称'
                            }
                        }
                    },
                    txtTotal: {
                        validators: {
                            notEmpty: {
                                message: '请输入数量'
                            },
                            numeric: {
                                message: '数量只能输入数字'
                            }
                        }
                    },
                    txtManager: {
                        validators: {
                            notEmpty: {
                                message: '请输入管理员'
                            }
                        }
                    },
                    txtDesc:{
                        stringLength : {
                            max : 100,
                            message : '不超过100个字符'
                        }
                    }
                }
            });
        }
        function renderImg() {
            $('#HeadImageUrl').dmUploader({ //
                url: '@Url.Action("UploadImg", "Product")',
                maxFileSize: 3000000, // 3 Megs max
                multiple: false,
                allowedTypes: 'image/*',
                extFilter: ['jpg', 'jpeg', 'png', 'gif'],
                onUploadSuccess: function (id, response) {
                    if (response.status==0) {
                        var oData = response.data;
                        $("#imgPhoto").attr("src",oData.HttpImgUrl);
                        $("#hidDbUrl").val(oData.ImgUrl);//存数据库里的相对路径
                        $("#divImg").show();
                        $("#hidImgPhoto-error").remove();
                    } else {
                        alert(response.data.message);
                    }
                }
            });
        }

    </script>
}






